Handle oneOf during schema generation#22
Merged
adrianhdezm merged 2 commits intomainfrom Jun 10, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for handling oneOf/anyOf constructs during schema-to-Zod and schema-to-Python-TypedDict generation, accompanied by new tests and a snapshot update.
- Extend
convertSchema(Zod) to emitz.union([...])foroneOf/anyOf - Extend
convertToTypedDict(Python) to emitUnion[...]foroneOf/anyOf - Add unit tests for
oneOfwith refs in both Zod and TypedDict paths and update snapshot
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/json-schema-to-zod.spec.ts | Added test for oneOf with refs |
| tests/json-schema-to-typed-dict.spec.ts | Added test for oneOf with refs |
| tests/snapshots/json-schema-to-typed-dict.spec.ts.snap | Updated snapshot for the new TypedDict union output |
| src/utils/json-schema-to-zod.ts | Implemented oneOf/anyOf handling for Zod schemas |
| src/utils/json-schema-to-typed-dict.ts | Implemented oneOf/anyOf handling for TypedDicts |
Comments suppressed due to low confidence (2)
tests/json-schema-to-zod.spec.ts:56
- [nitpick] Consider adding a corresponding test for
anyOfwith refs to ensure consistent coverage of both union keywords in Zod generation.
it('handles oneOf with refs', () => {
tests/json-schema-to-typed-dict.spec.ts:105
- [nitpick] It would be beneficial to add a test case for
anyOfwith refs so the Python TypedDict generator is equally exercised.
it('handles oneOf with refs', () => {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
oneOf/anyOfwhen generating Zod schemasoneOf/anyOfwhen generating PythonTypedDictsTesting
npm testhttps://chatgpt.com/codex/tasks/task_e_6848afbe2c3c832985d921d07e2976ee